<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS --><!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">
    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css"/>
    <!-- UNIFORM -->
    <link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css"/>
    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">

    <!-- file-input -->
    <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
    <!-- FONTS
    <link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
</head>
<body>
<header class="navbar clearfix" id="header">
</header>

<!-- PAGE -->
<section id="page">
    <!-- SIDEBAR -->
    <div id="sidebar" class="sidebar">
        <div class="sidebar-menu nav-collapse">

            <!-- SIDEBAR MENU -->
            <ul>
            </ul>
        </div>


    </div>
    <!-- /SIDEBAR -->
    <div id="main-content">
        <!-- SAMPLE BOX CONFIGURATION MODAL FORM-->

        <div class="container">
            <div class="row">
                <div id="content" class="col-lg-12">
                    <!-- PAGE HEADER-->
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="page-header">
                                <!-- STYLER -->

                                <!-- /STYLER -->
                                <!-- BREADCRUMBS -->
                                <ul class="breadcrumb">
                                    <li>
                                        <i class="fa fa-home"></i>
                                        <a href="index.html">首页</a>
                                    </li>
                                    <li>
                                        <a href="#">营销管理</a>
                                    </li>
                                    <li>优惠劵</li>
                                </ul>
                                <!-- /BREADCRUMBS -->

                            </div>
                        </div>
                    </div>
                    <!-- /PAGE HEADER -->
                    <!-- FORMS QUERY-->
                    <div class="row">
                        <div class="col-md-12">
                            <div class="row">
                                <div class="col-md-12"
                                     style="border: 1px solid #b6b6b6; margin-left: 15px;margin-bottom: 15px;width: 98%">
                                    <h5>1、发货模板请点击<a href="#" class="downloadOrderBtn" style="color:red">【这里】</a>下载,模板仅支持xlsx文件格式</h5>
                                    <h5>2、保存发货订单前，请确保导入数据准确。点击保存后，系统自动更新发货数据</h5>
                                </div>
                            </div>


                        </div>
                    </div>
                    <!-- /FORMS QUERY -->
                    <div class="row" style="height: 30px;">
                        <div class="col-md-12">
                            <div class="box ">


                                <div style="float:left; margin-left:5px; margin-right: 10px" class="addnewimg" id="f_span">
													<span class="btn btn-success btn-file" id="fir">
														<span  id="two">导入发货数据</span>
															<input name="uploadFile" upload-file="imageUrlProduct" type="file">
													</span>
                                    <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="margin-bottom: 0px; margin-top: 10px; display: none;">
                                        <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                                    </div>
                                </div>

                                <a href="javaScript:;" class="btn btn-warning saveBtn">
                                    	 确认发货
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <!-- TABLES -->
                        <div class="col-md-12">
                            <!-- BOX -->
                            <div class="box border primary">
                                <div class="box-title">
                                  导入行数<span id="total" style="color:red;margin-left:10px;margin-right:10px">0</span>行
                                </div>
                                <div class="box-body" style="min-height: 400px">
                                    <table id="db_Order_list" cellpadding="0" cellspacing="0" border="0"
                                           class="datatable table table-striped table-bordered table-hover">

                                    </table>
                                </div>
                            </div>
                            <!-- /BOX -->
                        </div>
                    </div>
                    <!-- /TABLES -->


                    <div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
                    </div>
                </div><!-- /CONTENT-->
            </div>
        </div>
    </div>
</section>
<!-- JQUERY -->
<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
<script src="../../js/common.js?v=20180119"></script>
<!-- JQUERY UI-->
<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
<!-- SLIMSCROLL -->
<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- bootstrap-fileupload -->
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>

<!-- INPUT MASK -->
<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
<!-- UNIFORM -->
<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
<!-- WIZARD -->
<script src="../../js/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
<!-- WIZARD -->
<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
<script src="../../js/jquery-validate/additional-methods.min.js"></script>
<script src="../../js/bootstrap-wizard/form-wizard.js"></script>
<!-- NESTABLE LISTS -->
<script type="text/javascript" src="../../js/nestable/jquery.nestable.min.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js?v=20180119"></script>

<script src="../../js/Sortable.min.js"></script>

<!-- DATA TABLES -->
<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>


<script>

    $(function () {
        var selectedTable;
        $("#header").load("../head.html");
        App.init(); //Initialise plugins and elements
        setMenu();
        $(".downloadOrderBtn").click(function () {
            location.href = App.getContextPath() + "admin/order/downloadSendOrderTemplate.do";

        });
        $("[upload-file=imageUrlProduct]").fileupload({
            url: App.getContextPath() + "admin/order/loadSendOrderExcel.do",
            dataType: 'json',
            acceptFileTypes: /(\.|\/)(xlsx)$/i,
            iframe: true,
            start: function (e) {
                $('.progress').fadeIn(300);
                return true;
            },
            autoUpload: true,
            done: function (e, data) {
                console.log(data.result);
                if(data.result.type == 'error') {
                    $.alert("导入模板错误");
                }else {
                	$("#total").html(data.result.extra.length);
                    initDateTable(data.result.extra);
                }

            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('.progress .progress-bar').css('width', progress + '%');
            }
        }).on('fileuploaddone', function (e, data) {
            $(".progress").fadeOut(300);

        });

        var initDateTable = function (data) {
        
            var dtSetting = $.dataTableSetting({
                "serverSide": false,
                "bFilter": false,// 去掉搜索框
                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "bSort": false,
                "paging": false,
                "data": data,
                "aoColumns": [{
                    "mDataProp": "orderId",
                    "sTitle": "订单编号",
                    "width": "10%"
                },{
                    "mDataProp": "provinceName",
                    "sTitle": "商品名称",
                    "width": "10%"
                },{
                    "mDataProp": "address",
                    "sTitle": "SKU编码",
                    "width": "10%"
                }, {
                    "mDataProp": "expressCompany",
                    "sTitle": "物流公司",
                    "width": "10%"
                }, {
                    "mDataProp": "expressCode",
                    "sTitle": "物流编号",
                    "width": "10%"
                }, {
                    "mDataProp": "areaName",
                    "sTitle": "错误提示",
                    "width": "10%",
                    "class":"red",
                    "render": function (data, type, row) {
                        return "<span style='color:red'>" + row.areaName + "</span>";
                    }
                }]

            });

            selectedTable = $("#db_Order_list").dataTable(dtSetting);

        }
        function contains(arr, obj) {
            var i = arr.length;
            while (i--) {
                if (arr[i].telPhone === obj.telPhone) {
                    return true;
                }
            }
            return false;
        }
        $(".saveBtn").click(function () {
            if(selectedTable  == null){
	           	 $.alert("请导入发货数据");
	           	 return;
            }
               
            var obj = selectedTable.api().rows().data();
            var datas = new Array();

           
            var amount = 0;
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].areaName != "") {
                    $.alert("请检查错误数据");
                    return;
                }
               
                datas.push(obj[i]);
            }
            var noRepeatArr = new Array();
            datas.forEach(function (e) {
                if(!contains(noRepeatArr,e)) {
                    noRepeatArr.push(e);
                }
            })
            
            if(datas==0){
                
              	 return;
              }
           	
            $.confirm("确认保存发货数据?", function () {

                datas = JSON.stringify(datas);
                $.blockUI();
                $.ajax({
                    type: "post",
                    url: App.getContextPath() + "admin/order/updateSendOrder.do",
                    data: {orderList: datas},
                    async: true,
                    success: function (result) {
                    	$.unblockUI();
                    	if(result.type=="error"){
                    		
                    		$.alert("以下订单编码已经退款："+result.extra.toString());
                    	}else{
                    		$.alert("发货成功");
                    		location.href = "send_order_list.html";
                    	}
                    	
                    }
                });
            })

        });

    });
</script>
</body>
</html>